package com.amap.api.col.s;

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import org.json.JSONObject;

/* compiled from: AAIDManager.java */
/* loaded from: classes.dex */
public class cn {
    private static cn a = null;
    private static boolean b = false;
    private static boolean c = false;
    private Context d;

    private cn(Context context) {
        this.d = context;
    }

    public static cn a(Context context) {
        if (a == null) {
            synchronized (cn.class) {
                if (a == null) {
                    a = new cn(context);
                }
            }
        }
        return a;
    }

    public final String a() {
        String str = "";
        try {
            if (ck.d) {
                str = cj.c(this.d);
                long d = cj.d(this.d);
                long elapsedRealtime = SystemClock.elapsedRealtime();
                if (!TextUtils.isEmpty(str)) {
                    if (elapsedRealtime - d > ck.b) {
                        ex.a().b(new ey() { // from class: com.amap.api.col.s.cn.2
                            @Override // com.amap.api.col.s.ey
                            public final void a() {
                                cn.this.c();
                            }
                        });
                    }
                } else {
                    ex.a().b(new ey() { // from class: com.amap.api.col.s.cn.1
                        @Override // com.amap.api.col.s.ey
                        public final void a() {
                            cn.this.b();
                        }
                    });
                }
            }
        } catch (Throwable unused) {
        }
        return str;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void b() {
        try {
            if (!b) {
                b = true;
                cl clVar = new cl(this.d);
                new dt();
                ea a2 = dt.a(clVar);
                if (a2 != null) {
                    JSONObject jSONObject = new JSONObject(ci.a(cm.a(a2.a, ci.c("YWDR1a2R2WEd0M3RXdHRocg==").getBytes())));
                    if (jSONObject.optBoolean("suc")) {
                        cj.f(this.d, clVar.a);
                        cj.g(this.d, clVar.b);
                        cj.h(this.d, clVar.c);
                        cj.i(this.d, clVar.d);
                        cj.j(this.d, clVar.e);
                        cj.k(this.d, clVar.f);
                        cj.l(this.d, clVar.g);
                        cj.b(this.d, clVar.i);
                        cj.m(this.d, clVar.h);
                        cj.a(this.d, SystemClock.elapsedRealtime());
                        String optString = jSONObject.optString("aaid", "");
                        String optString2 = jSONObject.optString("resetToken", "");
                        String optString3 = jSONObject.optString("uabc", "");
                        if (!TextUtils.isEmpty(optString)) {
                            cj.c(this.d, optString);
                        }
                        if (!TextUtils.isEmpty(optString2)) {
                            cj.e(this.d, optString2);
                        }
                        if (!TextUtils.isEmpty(optString3)) {
                            cj.d(this.d, optString3);
                        }
                    }
                }
                b = false;
                return;
            }
            b = false;
        } catch (Throwable unused) {
            b = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void c() {
        try {
            if (!c) {
                c = true;
                co coVar = new co(this.d);
                new dt();
                ea a2 = dt.a(coVar);
                if (a2 != null) {
                    JSONObject jSONObject = new JSONObject(ci.a(cm.a(a2.a, ci.c("YWDR1a2R2WEd0M3RXdHRocg==").getBytes())));
                    if (jSONObject.optBoolean("suc")) {
                        cj.f(this.d, coVar.a);
                        cj.g(this.d, coVar.b);
                        cj.h(this.d, coVar.c);
                        cj.i(this.d, coVar.d);
                        cj.j(this.d, coVar.e);
                        cj.k(this.d, coVar.f);
                        cj.l(this.d, coVar.g);
                        cj.b(this.d, coVar.i);
                        cj.m(this.d, coVar.h);
                        cj.a(this.d, SystemClock.elapsedRealtime());
                        String optString = jSONObject.optString("aaid", "");
                        String optString2 = jSONObject.optString("resetToken", "");
                        String optString3 = jSONObject.optString("uabc", "");
                        if (!TextUtils.isEmpty(optString)) {
                            cj.c(this.d, optString);
                        }
                        if (!TextUtils.isEmpty(optString2)) {
                            cj.e(this.d, optString2);
                        }
                        if (!TextUtils.isEmpty(optString3)) {
                            cj.d(this.d, optString3);
                        }
                    }
                }
                c = false;
                return;
            }
            c = false;
        } catch (Throwable unused) {
            c = false;
        }
    }
}
